//
//  FeedbackController.m
//  SettingsPage
//
//  Created by CPX on 2018/6/14.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "FeedbackController.h"
#import "UITextView+ZWPlaceHolder.h"

/**
 反馈页
 */
@interface FeedbackController ()

@property (nonatomic,strong) UITextView *contentTV;
@property (nonatomic,strong) UITextView *contactTV;

@end

@implementation FeedbackController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [FIRAnalytics logEventWithName:@"click_feedback" parameters:nil];
    [self initUI];
    
}

- (void)initUI{
    [self initNavigation];
    
    self.view.backgroundColor = UIColorHex(#F4F4F4);
    
    self.contentTV = [[UITextView alloc] initWithFrame:CGRectMake(16, 10+NavHeight, kScreenWidth-32, 120)];
    self.contentTV.backgroundColor = [UIColor whiteColor];
    self.contentTV.font = [UIFont systemFontOfSize:14];
    self.contentTV.zw_placeHolder = TLString(@"Fb_1");
    self.contentTV.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.contentTV.zw_placeHolderColor = UIColorHex(#33413988);
    [self.view addSubview:self.contentTV];
    
    UILabel *label = [UILabel new];
    label.text = TLString(@"Fb_21");
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = UIColorHex(#334139);
    [label sizeToFit];
    label.left = 16;
    label.top = self.contentTV.bottom + 24;
    [self.view addSubview:label];
    
    self.contactTV = [[UITextView alloc] initWithFrame:CGRectMake(16, label.bottom+12, kScreenWidth-32, 50)];
    self.contactTV.backgroundColor = [UIColor whiteColor];
    self.contactTV.font = [UIFont systemFontOfSize:14];
    self.contactTV.zw_placeHolder = TLString(@"Fb_2");
    self.contactTV.textContainerInset = UIEdgeInsetsMake(15, 10, 10, 10);
    self.contactTV.zw_placeHolderColor = UIColorHex(#33413988);
    [self.view addSubview:self.contactTV];
    
    UIButton *send = [UIButton buttonWithType:UIButtonTypeCustom];
    [send setBackgroundColor:UIColorHex(#00732F)];
    [send setTitle:TLString(@"Fb_3") forState:UIControlStateNormal];
    [send setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [send addTarget:self action:@selector(onSendTouched) forControlEvents:UIControlEventTouchUpInside];
    send.frame = CGRectMake(16, self.contactTV.bottom+85, kScreenWidth - 32, 55);
    send.layer.cornerRadius = 5;
    send.layer.masksToBounds = YES;
    [self.view addSubview:send];
}

- (void)initNavigation{
    [self.navigationController setNavigationBarHidden:YES];
    
    [self initLeftBackNaviButton];
    
    [self.myNavigationBar.backButton setTitle:TLString(@"Feedback") forState:UIControlStateNormal];
}

- (void)onSendTouched{
    if (self.contentTV.text.length) {
        [self.navigationController popViewControllerAnimated:NO];
        [self launchMailApp];
    }
    else{
        [MBProgressTool showTextForView:self.view text:TLString(@"Fb_1")];
    }
}

#pragma mark - 使用系统邮件客户端发送邮件
-(void)launchMailApp
{
    NSString *body = [NSString stringWithFormat:@"%@\n\n%@",self.contentTV.text,self.contactTV.text];
    NSString *mailUrl = [NSString stringWithFormat:@"mailto:muslimplusfeedback@gmail.com?subject=%@&body=%@",TLString(@"Feedback"),body];
    mailUrl = [mailUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString:mailUrl]];
}

@end
